package com.hfuu.controller.activity;

import com.github.pagehelper.PageInfo;
import com.hfuu.model.ResponseEntity;
import com.hfuu.model.ResponseEntityBuilder;
import com.hfuu.service.activity.ActivityService;
import com.hfuu.service.activity.request.ActivityRequest;
import com.hfuu.service.activity.request.PublishActivityRequest;
import com.hfuu.service.activity.response.ActivitySubjectResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.ws.rs.core.MediaType;
import java.util.List;

@Api(tags="活动控制类")
@RestController
@RequestMapping("/api/activity")
public class ActivityController {

    @Autowired
    private ActivityService activityService;

    @ApiOperation("条件查询活动")
    @RequestMapping(value = "/listActivity", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON)
    @ResponseBody
    public ResponseEntity<PageInfo> listActivity(@RequestBody ActivityRequest request)
            throws Exception{
        return ResponseEntityBuilder.success(activityService.listActivity(request));
    }

    @ApiOperation("查询活动主题")
    @RequestMapping(value = "/listActivitySubject", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON)
    @ResponseBody
    public ResponseEntity<List<ActivitySubjectResponse>> listActivitySubject(@RequestBody ActivityRequest request)
            throws Exception{
        return ResponseEntityBuilder.success(activityService.listActivitySubject(request));
    }

    @ApiOperation("发起或者编辑活动")
    @RequestMapping(value = "/insertOrUpdateActivity", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON)
    @ResponseBody
    public ResponseEntity<Integer> insertOrUpdateActivity(@RequestBody PublishActivityRequest request)
            throws Exception{
        return ResponseEntityBuilder.success(activityService.insertOrUpdateActivity(request));
    }

    @ApiOperation("删除一个活动")
    @RequestMapping(value = "/deleteActivityById", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON)
    @ResponseBody
    public ResponseEntity<Integer> deleteActivityById(@RequestBody ActivityRequest request)
            throws Exception{
        return ResponseEntityBuilder.success(activityService.deleteActivityById(request));
    }

    @ApiOperation("活动报名")
    @RequestMapping(value = "/attendActivity", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON)
    @ResponseBody
    public ResponseEntity<Boolean> attendActivity(@RequestBody ActivityRequest request)
            throws Exception{
        return ResponseEntityBuilder.success(activityService.attendActivity(request));
    }

    @ApiOperation("募捐插入活动记录表")
    @RequestMapping(value = "/attendFunActivity", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON)
    @ResponseBody
    public ResponseEntity<Boolean> attendFunActivity(@RequestBody ActivityRequest request)
            throws Exception{
        return ResponseEntityBuilder.success(activityService.attendFunActivity(request));
    }
}
